{include file="inc/header.html"}
<?php
$this->_var['dealcss'][] = $this->_var['TMPL_REAL']."/css/deal.css";
?>
<link rel="stylesheet" type="text/css" href="{function name="parse_css" v="$dealcss"}" />
	<div id="deal-default" class="clearfix">
		<p class="pos">
			<a href="{url x="index" r="index"}">首页</a> > <a href="{url x="index" r="deals"}">投资列表</a> > 借款详情
		</p>
		<div id="deal-intro" class="clearfix cf">
			<div class="tl">
				<div class="lf">
					<span><a href="{$deal.url}">{$deal.color_name}</a></span>
					<img src="{$deal.cate_info.icon}" title="{$deal.cate_info.name}" />
					&nbsp;&nbsp;
					借款人：<a href="{$u_info.url}" class="f_red" style="padding:0">{$u_info.user_name}</a>
				</div>
				<div class="rt detail_number">
					<a href="javascript:void(0);" class="f_blue" onclick="openWeeboxFrame('{url x="index" r="tool#contact" p="win=1&id=$deal.id"}','借款协议（范本）',1024,400);" >借款协议（范本）&nbsp;&nbsp;&nbsp;&nbsp;</a>
			
				</div>
			</div>
			<div class="bd">
				<div class="bd_lf">
					<table class="bd_1" width="100%" border="0" cellpadding="18" cellspacing="1">
						<tbody>
							<tr>
								<th>借款金额（元）</th>
								<th width="160">年利率</th>
								<th width="120">还款期限</th>
								<th width="90">风险等级</th>
							</tr>
							<tr>
								<td>{$deal.borrow_amount_format}</td>
								<td>{$deal.rate_foramt}%</td>
								<td>{$deal.repay_time}{if $deal.repay_time_type eq 0}天{else}个月{/if}</td>
								<td>{if $deal.risk_rank eq 0}低{elseif $deal.risk_rank eq 1}中{elseif $deal.rish_rank eq 2}高{/if}</td>
							</tr>
						</tbody>
					</table>
					<div class="bd_2">
						<div class="lf">
							<ul class="bd_2_lf">
								{if $deal.uloadtype eq 1}
								<li>出借单位：<span>{$deal.min_loan_money_format}</span></li>
								{/if}
								<li>还款方式：<span>{function name="loantypename" v="$deal.loantype" type=0}</span></li>
								<li>
									{if $deal.loantype eq 2 || $deal.repay_time_type eq 0}
										到期利息：<span class="f_red">{$deal.month_repay_money_format}</span>
									{else}
										月还{if $deal.loantype eq 0}本{else}利{/if}息：<span class="f_red">{$deal.month_repay_money_format}</span>
									{/if}
								</li>
							
								{if $deal.uloadtype eq 1}
								<li>最大认购：<span>{$deal.max_portion}</span> 份</li>
								{/if}
								<li>借款用途：<span>{$deal.type_info.name}</span></li>
								<li>担保范围：<span>{if $deal.warrant eq 1}本金{elseif $deal.warrant eq 2}本金及利息{else}无{/if}</span></li>
								<li>
									{if $deal.loantype eq 1 || $deal.loantype eq 2 }
										到期需还本金：<span class="f_red">{$deal.borrow_amount_format}</span>
									{/if}
								</li>
							</ul>
						</div>
						<div class="rt">
							<div class="f_l" style="width:140px;">
							 	{if $deal.is_delete eq 2}
									<img src="{$TMPL}/images/not_publish.png" alt="" width="134px" height="128px">
								{elseif $deal.is_wait eq 1}
									<img src="{$TMPL}/images/wait_load.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 5}
									<img src="{$TMPL}/images/load_done.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 4}
									<img src="{$TMPL}/images/load_in_progress.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 0}
									<img src="{$TMPL}/images/loan_writeM.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 1 && $deal.remain_time gt 0}
									<img src="{$TMPL}/images/load.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 2}
									<img src="{$TMPL}/images/load_full.png" alt="" width="134px" height="128px">
								{elseif $deal.deal_status eq 3 || $deal.remain_time lte 0}
									<img src="{$TMPL}/images/load_fail.png" alt="" width="134px" height="128px">
								{/if}
							</div>
						</div>
					</div>
				</div>
				<div class="bd_rt">
					<div class="dsjbox">
						<p>{if $deal.is_wait}开始{else}剩余{/if}时间</p>
						<div class="J_left_time dsj" id="dsj" rel="{$deal.remain_time}">
							<span class="s day">--</span>
							<span class="l">天</span>
							<span class="s hour">--</span>
							<span class="l">时</span>
							<span class="s min">--</span>
							<span class="l">分</span>
							<span class="s sec">--</span>
							<span class="l">秒</span>
						</div>
					</div>
					<script type="text/javascript">
						var leftTimeActInv = null;
						jQuery(function(){
							leftTimeAct();
						});
						function leftTimeAct(){
							clearTimeout(leftTimeActInv);
							$(".J_left_time").each(function(){
								var leftTime = parseInt($(this).attr("rel"));
								if(leftTime > 0)
								{
									var day  =  parseInt(leftTime / 24 /3600);
									var hour = parseInt((leftTime % (24 *3600)) / 3600);
									var min = parseInt((leftTime % 3600) / 60);
									var sec = parseInt((leftTime % 3600) % 60);
									$(this).find(".day").html((day<10?"0"+day:day));
									$(this).find(".hour").html((hour<10?"0"+hour:hour));
									$(this).find(".min").html((min<10?"0"+min:min));
									$(this).find(".sec").html((sec<10?"0"+sec:sec));
									leftTime--;
									$(this).attr("rel",leftTime);
								}
								else{
									$(this).css("background","none");
									$(this).html('<p style="font-size:16px;color:#999">时间已结束</p>');
								}
							});
							
							leftTimeActInv = setTimeout(function(){
								leftTimeAct();
							},1000);
						}
					</script>
					<div class="moneybox">
						<div class="money_l">
							<p>可投{if $deal.uloadtype eq 0}金额{else}份数{/if}</p>
							<span class="f_blue f18">{if $deal.uloadtype eq 0}{$deal.need_money}{else}{$deal.need_portion}{/if}</span>
						</div>
						<div class="money_r">
							<p><span class="f_l mr10" style="font-size:14px">账户余额</span><a href="{url x="index" r="uc_money#incharge"}" target=_blank class="recharge">充值</a></p>
							<div class="blank0"></div>
							<span class="f18 J_u_money_0" style="color:#19baaa">{function name="format_price" v="$user_info.money"}</span>
						</div>
						
					</div>
					
					<div class="blank1"></div>
						{if $user_info}
						{if $deal.deal_status eq 1 && $deal.remain_time gt 0}
						<div class="touzbox {if $deal.uloadtype eq 1}c_number-box{/if}">
							{if $deal.uloadtype eq 1}
							<a href="javascript:void(0);" class="c_number mt3" rel="-">-</a><input class="f-input mt3 c_number_ipt"  autocomplete="off" name="bid_money" id="J_BIDMONEY" value="1" /><a href="javascript:void(0);" class="c_number mt3"  rel="+">+</a>&nbsp;份,
							收益：<span class="J_u_money_sy f_red">0.00</span>
							<div class="blank1"></div>
							<div><span class="f_dgray">(已买<span class="f_red">{$has_bid_portion}</span>份{if $deal.max_portion}，最多可购买<span class="f_red">{$deal.max_portion}</span>份{/if})</div>
							{else}
							<span class="holder_tip">请输入投资金额</span>
							<input class="f-input"  autocomplete="off" name="bid_money" id="J_BIDMONEY" />
							<input type="hidden" name="id" value="{$deal.id}" />
							<span class="unit">元</span>
							<div class="blank5"></div>
							收益：<span class="J_u_money_sy f_red">0.00</span>
							{/if}
							<a href="javascript:void(0);" class="tz_link" id="tz_link">立即投资</a>
						</div>
						{/if}
						{else}
						<div class="touz-login"><a href="javascript:void(0);" onclick="ajax_login();" class="f_blue">您还没登录，请点击登录</a></div>
						{/if}
				</div>
				<div class="bd_bottom">
					{if  $deal.deal_status eq 5}
					<span class="f_l">还款进度：</span>
                    <div class="blueProgressBar progressBar f_l" style="border:1px solid #D13030; background:#FFC4C5">
                        <div class="p">
                        	<div class="c" style="width:100%;background:url('{$TMPL}/images/progressBarBg2.png') repeat-x"></div>
                       	</div>
                    </div>
                    {elseif $deal.deal_status eq 4}
                        <span class="f_l">还款进度：</span>
                        <div class="blueProgressBar progressBar f_l" style="border:1px solid #FDECC7; background:#FFF6E5">
                            <div class="p">
                            	<div class="c" style="width: {function name='round' val=$deal.repay_progress_point f=3}%;background:url('{$TMPL}/images/progressBarBg2.png') repeat-x"></div>
                           	</div>
                        </div>
                        <div class="f_l" style="width: 170px; padding-left:30px">
						已还本息：<span class="f_red">{function name="number_format" v=$deal.repay_money f=2}元</span>
                        </div>
                        <div class="f_l" style="width: 160px; ">
						待还本息：<span class="f_red">{function name="number_format" v=$deal.need_remain_repay_money f=2}元</span>
                        </div>
					{else}
                    <span style="float:left">投标进度：</span>
                    <div class="blueProgressBar progressBar f_l">
                        <div class="p">
                        	<div class="c" style="width:{function name='round' val=$deal.progress_point f=3}%;"></div>
                       	</div>
                    </div>
                    <div class="f_l">
                        <span class="f_red">&nbsp;&nbsp;
                        	{function name='round' val=$deal.progress_point f=0}% 
                       	</span>
						{if $deal.uloadtype eq 1}
						已认购 <font class="f_red">{$deal.buy_portion}</font> 份，还需 <font class="f_red">{$deal.need_portion}</font>  份
						{else}
                        <span class="f_red">{$deal.buy_count}</span> {$LANG.DEAL_BID_COUNT}，{$LANG.MUST_NEED_BID} <span class="f_red">{$deal.need_money}</span>
						{/if}
                    </div>
					{/if}
					{if $ACTION_NAME neq 'preview'}
					<div class="item f_r" style="width:auto" id="addFav">
						{if $deal.is_faved gt 0}
						已关注
						{else}
						<a href="javascript:;" id="addFavLink" onclick="collect_deal(this,'{$deal.id}',fav_result);" class="f_red">关注此标</a>
						{/if}
					</div>
					{/if}
				</div>
			</div>
		</div>
		<div class="blank"></div>
		<div class="blank"></div>
		<div class="desc_inf wrap clearfix">
	        <div class="list_title clearfix" id="J_deal_tab_select">
	            <ul>
	                <li class="list1 right_tab_select" style="cursor:pointer;" rel="1">借入者信用信息</li>
					{if $deal.deal_status gte 4}
					<li class="list1" style="cursor:pointer;" rel="2">还款详情</li>
					<li class="list1" style="cursor:pointer;" rel="3">债权人信息</li>
					{/if}
					<li class="list1" style="cursor:pointer;" rel="4">投标记录</li>
	            </ul>
	        </div>
			<div class="cont clearfix" id="J_deal_tab_box">
				<div class="box_view box_view_1">
					{include file="inc/deal/user_credit_info.html"}
					{include file="inc/deal/user_credit_passed_info.html"}
					{if $deal.agency_id gt 0}
					{include file="inc/deal/user_guarantee_info.html"}
					{/if}
					<p class="b" style="margin:30px 0 10px 0;">借款描述</p>
					<div class="clearfix" style="border-bottom:1px solid #e3e3e3; padding:0 0 20px 70px;">
						<span>{$deal.description}</span>
					</div>
					{if $ACTION_NAME neq 'preview'}
					{include file="inc/message_form.html"}
					{/if}
				</div>
				{if $deal.deal_status gte 4}
				<div class="box_view box_view_2 hide">
					{include file="inc/deal/loan_repay_list.html"}
				</div>
				<div class="box_view box_view_3 hide">
				{include file="inc/deal/load_repay_list.html"}
				</div>
				{/if}
				 <div class="box_view box_view_4 hide">
	               {include file="inc/deal/load_list.html"}
		        </div>
			</div>
		</div>
	</div>
<script type='text/javascript'>
	function fav_result(o)
	{
		$(o).html("已关注");
		$(o).addClass("f_red");
		$(o).attr("click","");
	}
	var is_submit_lock =false;
	var bid_paypassword = "";
	var bid_calculate = null;
	jQuery(function(){
		{if $deal.uloadtype eq 1}
		$("a.c_number").click(function(){
			var rel=$(this).attr("rel");
			var obj = $(this);
			var number = parseInt($("#J_BIDMONEY").val());
			switch(rel){
				case "-":
					if(number-1 > 1){
						$("#J_BIDMONEY").val(number-1);
					}
					else{
						$("#J_BIDMONEY").val(1);
					}
					break;
				case "+":
					 var max_portion = {if $deal.max_portion gt 0}<?php echo $this->_var['deal']['max_portion'] - $this->_var['has_bid_portion'];  ?>{else}{$deal.need_portion}{/if};
					if(number+1 <= max_portion){
						$("#J_BIDMONEY").val(number+1);
					}
					else{
						$("#J_BIDMONEY").val(max_portion);
					}
					break
			}
			loadSy();
		});
		{/if}
		$("#J_deal_tab_select li").click(function(){
			$("#J_deal_tab_select li").removeClass("right_tab_select");
			$("#J_deal_tab_select li").addClass("right_tab_unselect");
			$(this).removeClass("right_tab_unselect");
			$(this).addClass("right_tab_select");
			$("#J_deal_tab_box .box_view").addClass("hide");
			$("#J_deal_tab_box .box_view_"+$(this).attr("rel")).removeClass("hide");
		});
		
		$(".touzbox .holder_tip").click(function(){
			$(this).hide();
			$(this).parent().find(".f-input").focus();
		});
	
		$(".touzbox .f-input").focus(function(){
			$(this).parent().find(".holder_tip").hide();
		});
		$(".touzbox .f-input").blur(function(){
			if($(this).val()==""){
				$(this).parent().find(".holder_tip").show();
			}
		});
	
		$(".touzbox .f-input").each(function(){
			if($(this).val()==""){
				$(this).parent().find(".holder_tip").show();
			}
			else{
				$(this).parent().find(".holder_tip").hide();
			}
		});
		
		$("#tz_link").click(function(){
			{if $deal.uloadtype eq 0}
			if($.trim($("#J_BIDMONEY").val())=="" || !$.checkNumber($("#J_BIDMONEY").val()){if (int)app_conf('DEAL_BID_MULTIPLE') gt 0} || parseFloat($("#J_BIDMONEY").val())%{function name='app_conf' v='DEAL_BID_MULTIPLE'}!=0{/if} || parseFloat($("#J_BIDMONEY").val())<=0 || parseFloat($("#J_BIDMONEY").val())<{$deal.min_loan_money} {if $deal.max_loan_money gt 0}|| parseFloat($("#J_BIDMONEY").val())>{$deal.max_loan_money}{/if}){
				is_submit_lock = false;
				$.showErr(LANG.BID_MONEY_NOT_TRUE,function(){
					$("#J_BIDMONEY").focus();
				});
			
				return false;
			}
			{else}
			
				if($.trim($("#J_BIDMONEY").val())=="" || !$.checkNumber($("#J_BIDMONEY").val()) || parseInt($.trim($("#J_BIDMONEY").val())) <=0 || parseFloat($.trim($("#J_BIDMONEY").val()))%parseInt($.trim($("#J_BIDMONEY").val()))!=0){
					is_submit_lock = false;
					$.showErr("请输入正确的份数",function(){
						$("#J_BIDMONEY").focus();
					});
				
					return false;
				}
				
				{if $deal.max_portion gt 0}
					if(parseInt($.trim($("#J_BIDMONEY").val())) > <?php echo $this->_var['deal']['max_portion'] - $this->_var['has_bid_portion'];  ?>){
						is_submit_lock = false;
						$.showErr("您已经购买了{$has_bid_portion}份，还能购买<?php echo $this->_var['deal']['max_portion'] - $this->_var['has_bid_portion'];  ?>份",function(){
							$("#J_BIDMONEY").focus();
						});
					
						return false;
					}
				{else}
					if(parseInt($.trim($("#J_BIDMONEY").val())) > {$deal.need_portion}){
						is_submit_lock = false;
						$.showErr("您已经购买了{$has_bid_portion}份，还能购买{$deal.need_portion}份",function(){
							$("#J_BIDMONEY").focus();
						});
					
						return false;
					}
				{/if}
			{/if}
			
			var html='<div class="tc p15">';
				html +='支付密码：<input type="password" class="f-input" id="J_bid_password" />';
				html +='<div class="blank5"></div>';
				html +='{if $user_info.paypassword eq ''}还未设置！{else}忘记了？{/if}<a href="{url x="index" r="uc_account#security"}" target="_blank" class="f_blue">点这里</a>';
				html +='<div class="blank5"></div>';
				html +='<input type="button" class="sub_btn theme_bgcolor" id="J_bindpassword_btn" value="确定">&nbsp;&nbsp;';
				html +='<input type="button" class="reset_btn"  id="J_bindpassword_rbtn" value="取消">';
				html +="</div>";
			$.weeboxs.open(html,{boxid:"paypass-box",contentType:'text',showButton:false,title:"支付密码",width:380,height:140,type:'wee'});
			
		});
		
		$("#J_bindpassword_btn").live("click",function(){
			if($.trim($("#J_bid_password").val())!=""){
				bid_paypassword =$.trim($("#J_bid_password").val());
				to_load();
			}
			else{
				$.showErr("请输入支付密码",function(){
					$("#J_bid_password").focus();
				});
			}
		});
		$("#J_bindpassword_rbtn").live("click",function(){
			$.weeboxs.close("paypass-box");
		});
		
		$("#J_BIDMONEY").keyup(function(){
			loadSy();
		});
		
		loadSy();
		
		{if $deal.ips_bill_no neq "" && $user_info.id gt 0}
		checkIpsBalance(0,{$user_info.id},function(result){
			if(result.pErrCode=="0000"){
				$(".J_u_money_0").html(result.pBalance+"<span class='f_red '>[绑]</span>");
			}
		});
		{/if}
		
	});
	
	function loadSy(){
		var query = new Object();
		query.uloantype = '{$deal.uloadtype}';
		query.minmoney = '{$deal.min_loan_money}';
		query.loantype = '{$deal.loantype}';
		query.rate = '{$deal.rate}';
		query.repay_time = '{$deal.repay_time}';
		query.repay_time_type = '{$deal.repay_time_type}';
		query.money = $.trim($("#J_BIDMONEY").val());
		if(bid_calculate) bid_calculate.abort(); //终止之前所有的未结束的ajax请求，然后重新开始新的请求  
		bid_calculate = $.ajax({
			url:'{url x="index" r="ajax#bid_calculate"}',
			data:query,
			type:"post",
			dataType:"text",
			success:function(result){
				$(".J_u_money_sy").html(result);
			}
		});
	}
	
	function to_load(){
		if(is_submit_lock)
		{
			return false;
		}
		is_submit_lock = true;
		var query = new Object();
		query.bid_money=$.trim($("#J_BIDMONEY").val())
		query.id="{$deal.id}";
		query.bid_paypassword = FW_Password(bid_paypassword);
		query.ajax=1;
		
		$.ajax({
			url:'{url x="index" r="deal#dobid"}',
			data:query,
			type:"POST",
			dataType:"json",
			success:function(result){
				if(result.status==1){
					is_submit_lock = false;
					$.showSuccess(result.info,function(){
						window.location.reload();
					});
				}
				else if(result.status==2){
					window.location.href=result.jump;
				}
				else{
					is_submit_lock = false;
					$.showErr(result.info);
				}
			},
			error:function(ajaxobj)
			{
			}
		});
	}
</script>
{include file="inc/footer.html"}



								